CXXTARGETS = counting-sort csp-j-2023-reading-program-2

CTARGETS=

CFLAGS = -Wall -Wextra -Werror -O2 -g -std=c99
CXXFLAGS = -Wall -Wextra -Werror -O2 -g -std=c++14

UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S), Linux)
    CXXFLAGS += -DLINUX
endif
ifeq ($(UNAME_S), Darwin)
    CXXFLAGS += -DDARWIN
endif

ifeq ($(CXX), g++)
    CXXFLAGS += -fmax-errors=10
else ifeq ($(CXX), clang++)
    CXXFLAGS += -ferror-limit=10
endif

all:$(CXXTARGETS) $(CTARGETS)

$(CXXTARGETS):%:%.o
	$(CXX) -o $@ $<

$(CTARGETS):%:%.o
	$(CC) -o $@ $<

%.o:%.cpp
	$(CXX) -c $(CXXFLAGS) $< -o $@

%.o:%.c
	$(CC) -c $(CFLAGS) $< -o $@

.PHONY: clean

clean:
	rm -f *.o $(CXXTARGETS) $(CTARGETS)
